This chapter wraps a GGUF model in a local HTTP service. The pattern is deliberately plain: start llama-server, wait until /v1/models responds, send requests, collect timings, and terminate the process.
with running_server() as (base_url, command): models = requests.get(f"{base_url}/v1/models", timeout=10).json() row = models["data"][0]print(f"Serving from {base_url}")print(f"Model id: {row.get('id')}")print(f"Object type: {row.get('object')}")print(f"Command uses {len(command)} command-line arguments.")
server_mode: cpu_only
Serving from http://127.0.0.1:45717
Model id: qwen-local
Object type: model
Command uses 24 command-line arguments.
def native_completion(base_url: str, question: str) ->dict: prompt =f"Q: {question}\nA:" response = requests.post(f"{base_url}/completion", json={"prompt": prompt,"n_predict": 72,"temperature": 0,"stop": ["\nQ:"], }, timeout=90, ) response.raise_for_status() payload = response.json() timings = payload.get("timings", {})return {"question": question,"answer": payload.get("content", "").strip(),"predicted_tokens": timings.get("predicted_n"),"predicted_tokens_per_s": timings.get("predicted_per_second"), }questions = ["What is the role of llama-server in a local LLM application?","Why bind a development server to 127.0.0.1?","What should an application log for local model requests?",]with running_server() as (base_url, _): rows = [native_completion(base_url, question) for question in questions]served = pd.DataFrame(rows)served["predicted_tokens_per_s"] = served["predicted_tokens_per_s"].round(2)served
server_mode: full_gpu
question
answer
predicted_tokens
predicted_tokens_per_s
0
What is the role of llama-server in a local LLM application?
llama-server is a tool that provides a server-side interface for running LLMs locally. It allows users to interact w...
46
138.30
1
Why bind a development server to 127.0.0.1?
Because it's the only way to access the server from the local machine.
18
140.88
2
What should an application log for local model requests?
An application should log the following information for local model requests:\n1. Timestamp\n2. Model name\n3. Reque...
For application code, the important boundary is the HTTP contract, not the model binary. Keep the server command, model path, context size, quantization, and timing fields with the run metadata so later evaluations can distinguish model quality from serving configuration.